import Vue from 'vue'
import App from './App.vue'
import router from './router/index.js'
import store from './store'
import axios from 'axios'

Vue.prototype.$http = axios

let Vm = new Vue({
  el: '#app',
  render: h => h(App),
  store,
  router
})

router.afterEach((to, from) => {
  const login = store.state.userinfo.islogin
  if (login === true && to.path === '/registerPage') {
    router.push({ path: '/homePage' })
  } else if (login === true && to.path === '/loginPage') {
    alert('请先退出!')
    router.push({ path: '/homePage' })
  } else if (login === false && to.path === '/selfLife') {
    alert('请先登陆！')
    router.push({ path: '/loginPage' })
  } else if (login === false && to.path === '/selfBlog') {
    alert('请先登陆！')
    router.push({ path: '/loginPage' })
  } else if (login === false && to.path === '/editBlog') {
    alert('请先登陆！')
    router.push({ path: '/loginPage' })
  } else if (login === false && to.path === '/userPage/checkInfo') {
    alert('请先登陆！')
    router.push({ path: '/loginPage' })
  } else if (login === false && to.path === '/userPage/editInfo') {
    alert('请先登陆！')
    router.push({ path: '/loginPage' })
  }
})

Vue.use({
  Vm
})
